package com.hjm.project.terminal.posCount.controller;

import com.hjm.common.utils.StringUtils;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.page.TableDataInfo;
import com.hjm.project.terminal.posCount.domain.PosCount;
import com.hjm.project.terminal.posCount.service.PosCountService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 终端型号Controller
 * 
 * @author LOVE
 * @date 2020-11-26
 */
@Controller
@RequestMapping("/terminal/posCount")
public class PosCountController extends BaseController
{
    private String prefix = "terminal/posCount";

    @Resource
    private PosCountService posCountService;

    @GetMapping()
    public String model(ModelMap mmap) throws Exception {
        return prefix + "/posCount";
    }

    /**
     * 展业端管理达标量
     * @Param [mmap]
     * @Return java.lang.String
     */
    @GetMapping("/twoCount")
    public String twoCount(ModelMap mmap) throws Exception {
        return prefix + "/twoCount";
    }
    /**
     * 展业端管理终端汇总
     * @Param [mmap]
     * @Return java.lang.String
     */
    @GetMapping("/posSum")
    public String posSum(ModelMap mmap) throws Exception {
        return prefix + "/posSum";
    }

    /**
     * 获取展业端管理激活量(一段达标)
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PosCount posCount) throws Exception {
        //开始时间
        if (posCount != null && StringUtils.isNotEmpty(posCount.getStartDate())) {
            posCount.setStartDate(posCount.getStartDate() + " 00:00:00");
        }
        if (posCount != null && StringUtils.isNotEmpty(posCount.getEndDate())) {
            posCount.setEndDate(posCount.getEndDate() + " 23:59:59");
        }
        PosCount sumCount = posCountService.selectPosCountSum(posCount);
        startPage();
        List<PosCount> list = posCountService.selectPosCountList(posCount);
        return getDataTable(list,sumCount);
    }


    /**
     * 获取展业端管理达标量(除一段达标外的数据)
     */
    @PostMapping("/twoList")
    @ResponseBody
    public TableDataInfo twoList(PosCount posCount) throws Exception {
        //开始时间
        if (posCount != null && StringUtils.isNotEmpty(posCount.getStartDate())) {
            posCount.setStartDate(posCount.getStartDate() + " 00:00:00");
        }
        if (posCount != null && StringUtils.isNotEmpty(posCount.getEndDate())) {
            posCount.setEndDate(posCount.getEndDate() + " 23:59:59");
        }
        startPage();
        List<PosCount> list = posCountService.selectPosTwoCountList(posCount);
        return getDataTable(list);
    }



    /**
     * 获取展业端管理达标量(除一段达标外的数据)
     */
    @PostMapping("/posCountSumList")
    @ResponseBody
    public TableDataInfo posCountSumList(PosCount posCount) throws Exception {
        List<PosCount> list = new ArrayList<>();;
        if (StringUtils.isNotEmpty(posCount.getAgentNum())) {
            list = posCountService.selectAgentPosCountOne(posCount);
        }
        return getDataTable(list);
    }


}
